package files

import (
	"github.com/duke-git/lancet/v2/fileutil"
	"github.com/sirupsen/logrus"
	"os"
	"path/filepath"
)

// Mkdir 级联创建目录，可以是相对路径或绝对路径. 返回绝对路径
// 例 ./data  data  /var/data
func Mkdir(_path string) (string, error) {

	if !fileutil.IsExist(_path) {
		err := os.MkdirAll(_path, 0755)
		if err != nil {
			logrus.Error("无法创建目录 {}", _path, err)
			return "", err
		}
	}

	fullPath, err := filepath.Abs(_path)
	if err != nil {
		logrus.Error("无法获取绝对路径 {}", fullPath, err)
		return "", err
	}

	return fullPath, nil
}
